package com.my.chapter14;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class practice15 {
    public static void main(String[] args) {
        for(int i=0;i<10;i++){
            System.out.println(Pet2.createRandom());
        }
    }
}

class Pet2{
    static List<Factory<? extends Pet2>>  petFactories = new ArrayList<Factory<? extends Pet2>>();
    static {
        petFactories.add(new Dog2.Factory());
        petFactories.add(new Mutt2.Factory());
        petFactories.add(new Pug2.Factory());
        petFactories.add(new Cat2.Factory());
        petFactories.add(new EgyptianMau2.Factory());
        petFactories.add(new Manx2.Factory());
        petFactories.add(new Cymric2.Factory());
        petFactories.add(new Rat2.Factory());
        petFactories.add(new Mouse2.Factory());
        petFactories.add(new Hamster2.Factory());
        petFactories.add(new Gerbil2.Factory());
    }
    private static Random rand = new Random(47);
    public static Pet2 createRandom(){
        int n = rand.nextInt(petFactories.size());
        return petFactories.get(n).create();
    }

    @Override
    public String toString() {
        return getClass().getSimpleName();
    }
}

class Dog2 extends Pet2{
    public static class Factory
    implements com.my.chapter14.Factory<Dog2>{

        @Override
        public Dog2 create() {
            return new Dog2();
        }
    }

    @Override
    public String toString() {
        return "Dog";
    }
}

class Mutt2 extends Dog2{
    public static class Factory
            implements com.my.chapter14.Factory<Mutt2>{

        @Override
        public Mutt2 create() {
            return new Mutt2();
        }
    }

    @Override
    public String toString() {
        return "Mutt";
    }
}

class Pug2 extends Dog2{
    public static class Factory
            implements com.my.chapter14.Factory<Pug2>{

        @Override
        public Pug2 create() {
            return new Pug2();
        }
    }

    @Override
    public String toString() {
        return "Pug";
    }
}

class Cat2 extends Pet2{
    public static class Factory
            implements com.my.chapter14.Factory<Cat2>{

        @Override
        public Cat2 create() {
            return new Cat2();
        }
    }

    @Override
    public String toString() {
        return "Cat";
    }
}

class EgyptianMau2 extends Pet2{
    public static class Factory
            implements com.my.chapter14.Factory<EgyptianMau2>{

        @Override
        public EgyptianMau2 create() {
            return new EgyptianMau2();
        }
    }

    @Override
    public String toString() {
        return "EgyptianMau";
    }
}

class Manx2 extends Pet2{
    public static class Factory
            implements com.my.chapter14.Factory<Manx2>{

        @Override
        public Manx2 create() {
            return new Manx2();
        }
    }

    @Override
    public String toString() {
        return "Manx";
    }
}

class Cymric2 extends Manx2{
    public static class Factory
            implements com.my.chapter14.Factory<Cymric2>{

        @Override
        public Cymric2 create() {
            return new Cymric2();
        }
    }


    @Override
    public String toString() {
        return "Cymric";
    }
}

class Rodent2 extends Pet2{
    public static class Factory
            implements com.my.chapter14.Factory<Rodent2>{

        @Override
        public Rodent2 create() {
            return new Rodent2();
        }
    }

    @Override
    public String toString() {
        return "Rodent";
    }
}

class Rat2 extends Rodent2{
    public static class Factory
            implements com.my.chapter14.Factory<Rat2>{

        @Override
        public Rat2 create() {
            return new Rat2();
        }
    }

    @Override
    public String toString() {
        return "Rat";
    }
}

class Mouse2 extends Rodent2{
    public static class Factory
            implements com.my.chapter14.Factory<Mouse2>{

        @Override
        public Mouse2 create() {
            return new Mouse2();
        }
    }

    @Override
    public String toString() {
        return "Mouse";
    }
}

class Hamster2 extends Rodent2{
    public static class Factory
            implements com.my.chapter14.Factory<Hamster2>{

        @Override
        public Hamster2 create() {
            return new Hamster2();
        }
    }

    @Override
    public String toString() {
        return "Hamster";
    }
}

class Gerbil2 extends Pet2{
    public static class Factory
            implements com.my.chapter14.Factory<Gerbil2>{

        @Override
        public Gerbil2 create() {
            return new Gerbil2();
        }
    }

    @Override
    public String toString() {
        return "Gerbil";
    }
}


